package com.ouken.com;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

import com.gen.tool.SoundPlayer;
import com.ouken.asynTask.AsynGetRanklist;
import com.ouken.asynTask.AsynGetdic;
//import com.ouken.tool.MplayerTool;
import com.ouken.tool.MyApp;
import com.vick.com.AboutusActivity;
import com.vick.com.ManualActivity;

public class HPActivity extends Activity {
	private MyApp appState;
	private SharedPreferences userInfo;
	private ImageButton ib_account;
	private ImageButton ib_ranklist;
	private ImageButton ib_setting;
	private ImageButton ib_mydic;
	private ImageButton ib_logoff;
	private ImageButton ib_startgame;
	private ImageButton ib_manual, ib_aboutus;
	//private MplayerTool mplayerTool;
	private Context context;

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		SoundPlayer.pauseMusic();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		SoundPlayer.startMusic();
	}

	private void initView() {

		userInfo = getSharedPreferences("user_info", 0);
		appState = ((MyApp) getApplicationContext());
		//appState.setMusic(userInfo.getString("MUSIC", "ON").equals("ON"));
		appState.addActivity(HPActivity.this);

		ib_account = (ImageButton) findViewById(R.id.HPActivity_ib_account);
		ib_ranklist = (ImageButton) findViewById(R.id.HPActivity_ib_ranklist);
		ib_setting = (ImageButton) findViewById(R.id.HPActivity_ib_setting);
		ib_mydic = (ImageButton) findViewById(R.id.HPActivity_ib_mydictionary);
		ib_logoff = (ImageButton) findViewById(R.id.HPActivity_ib_logoff);
		ib_startgame = (ImageButton) findViewById(R.id.HPActivity_ib_startgame);
		ib_aboutus = (ImageButton) findViewById(R.id.HPActivity_ib_aboutus);
		ib_manual = (ImageButton) findViewById(R.id.HPActivity_ib_manual);
		//mplayerTool = new MplayerTool(HPActivity.this);

		context = HPActivity.this;
		

	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hp);
		initView();
		

		ib_account.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playButtonPressed(HPActivity.this);
				SoundPlayer.playSound(R.raw.keypress_common);
				Intent intent = new Intent(HPActivity.this,
						AccountActivity.class);
				startActivity(intent);

			}
		});
		ib_ranklist.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playButtonPressed(HPActivity.this);
				SoundPlayer.playSound(R.raw.keypress_common);
				new AsynGetRanklist(context, appState).execute();

			}
		});

		ib_setting.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playButtonPressed(HPActivity.this);
				SoundPlayer.playSound(R.raw.keypress_common);
				Intent intent = new Intent(HPActivity.this,
						SettingActivity.class);
				startActivity(intent);
			}
		});
		ib_mydic.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playButtonPressed(HPActivity.this);
				SoundPlayer.playSound(R.raw.keypress_common);
				new AsynGetdic(context, appState).execute();
			}
		});

		ib_logoff.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playButtonPressed(HPActivity.this);
				SoundPlayer.playSound(R.raw.keypress_common);
				userInfo.edit().putString("AUTOLOGIN", "NO").commit();

				appState.killAllActivities();
				Intent intent = new Intent(HPActivity.this, LoginActivity.class);
				startActivity(intent);
			}
		});

		ib_startgame.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playBackGroundMusic(HPActivity.this);
				//mplayerTool.playButtonPressed(HPActivity.this);
				// asynGetRoomlist = new AsynGetRoomlist(context, appState, "");
				// asynGetRoomlist.execute();
				SoundPlayer.playSound(R.raw.keypress_common);
				Intent intent = new Intent(HPActivity.this,
						RoomlistActivity.class);
				startActivity(intent);
				SoundPlayer.stopMusic();

			}
		});

		// ------- vick add -------------
		ib_manual.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playButtonPressed(HPActivity.this);
				SoundPlayer.playSound(R.raw.keypress_common);
				Intent intent = new Intent(HPActivity.this,
						ManualActivity.class);
				startActivity(intent);
			}
		});
		ib_aboutus.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				//mplayerTool.playButtonPressed(HPActivity.this);
				SoundPlayer.playSound(R.raw.keypress_common);
				Intent intent = new Intent(HPActivity.this,
						AboutusActivity.class);
				startActivity(intent);
			}
		});
	}
}
